//good
#include <bits/stdc++.h>
using namespace std;

const int N = 1e6 + 10;
int n, m, a[N], rs;
char s[N];

struct node{
    int sum, am, lm, rm;
} t[N*4];

void upd(node &p, node l, node r){
    p.sum = l.sum + r.sum;
    p.lm = max(l.lm, l.sum + r.lm);
    p.rm = max(r.rm, r.sum + l.rm);
    p.am = max(l.am, r.am);
    p.am = max(p.am, l.rm + r.lm);
}
void build(int p, int l, int r){
    if(l == r){
        t[p].sum = (s[l] == '1' ? 1 : -1);
        t[p].am = t[p].lm = t[p].rm = max(0, t[p].sum);
    } else {
        int mid = l + r >> 1;
        build(p<<1, l, mid);
        build(p<<1|1, mid+1, r);
        upd(t[p], t[p<<1], t[p<<1|1]);
    }
}
node ask(int p, int l, int r, int ql, int qr){
    if(ql <= l && r <= qr){
        return t[p];
    } else {
        int mid = l + r >> 1;
        if(qr <= mid){
            return ask(p<<1, l, mid, ql, qr);
        } else if(mid < ql){
            return ask(p<<1|1, mid+1, r, ql, qr);
        } else {
            node qq;
            upd(qq, ask(p<<1, l, mid, ql, qr),
                    ask(p<<1|1, mid+1, r, ql, qr));
            return qq;
        }
    }
}

int main(){
    freopen("good.in", "r", stdin);
    freopen("good.out", "w", stdout);
    scanf("%d%d", &n, &m);
    scanf("%s", s+1);
    for(int i = 1; i <= n; ++ i){
        if(s[i] == '1'){
            a[i] = a[i-1] + 1;
        } else {
            a[i] = a[i-1] - 1;
        }
    }
    build(1, 1, n);
    for(int i = 1; i <= m; ++ i){
        int l, r;
        scanf("%d%d", &l, &r);
        int x = ask(1, 1, n, l, r).am;
        x = max(x, 1);
        int y = a[r] - a[l-1];
        rs ^= (x-y);
        // printf("%d %d %d\n", x, y, x-y);
    }
    printf("%d\n", rs);
    return 0;
}